
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FactoryListResult extends JFrame{
    public FactoryListResult(String mUID,String typeID){

        SQLOperation sql=new SQLOperation();

        setTitle("Equipment List");
        Container container=getContentPane();
        setLayout(new BorderLayout());

        JPanel titlePanel=new JPanel();

        JLabel title=new JLabel("Selected Type Equipment Information");
        title.setFont(new Font("",Font.BOLD,20));

        titlePanel.add(title);

        String[] deviceAttributes={"idDevice","Family_familyID","DeviceType_typeID"};
        String[] accountAttributes={"tName"};
        String[] attributes={"DeviceID","familyID","typeID","typeName"};
        Object[][] deviceDB=sql.search("Device",deviceAttributes,"Manufacture_mUID",mUID);


        int pass=0;
        for(int i=0;i< deviceDB.length;i++) {
            if (deviceDB[i][1].equals("0") || deviceDB[i][1].equals("") || (!deviceDB[i][2].equals(typeID))) {
                pass++;
            }
        }
        Object[][] deviceList=new Object[deviceDB.length-pass][4];
        pass=0;
        for(int i=0;i< deviceDB.length;i++){
            if(deviceDB[i][1].equals("0")||deviceDB[i][1].equals("")||(!deviceDB[i][2].equals(typeID))){
                pass++;
            }
            else {
                for (int j = 0; j <3; j++) deviceList[i-pass][j] = deviceDB[i][j];
                deviceList[i-pass][3] = sql.search("DeviceType", accountAttributes, "typeID", deviceDB[i][2])[0][0];
            }
        }








        JTable deviceTable=new JTable(deviceList,attributes);
        deviceTable.setRowHeight(30);
        deviceTable.setFont(new Font("",Font.PLAIN,15));

        deviceTable.setEnabled(true);
        deviceTable.getTableHeader().setFont(new Font("",Font.BOLD,20));
        JScrollPane scrollPane=new JScrollPane(deviceTable);

        add(scrollPane,BorderLayout.CENTER);

        JButton back=new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });


        JPanel buttons=new JPanel();
        buttons.add(back);


        add(buttons,BorderLayout.SOUTH);






        setSize(600,500);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);



    }
}
